#include "TestComboBoxForm.h"


#define LOWERCASE 0x1
#define UPPERCASE 0x2
#define AUTOSORT 0x4
#define HSCROLL 0x8
#define SHOWSCROLL 0x10
#define STYLE_MASK 0x00ff

#define SIMPLE 0x1000
#define DROPDOWN 0x2000
#define DROPDOWNLIST 0x3000
#define TYPE_MASK 0xf000


static struct ControlInfo {

	WORD ID;
	const wchar_t* Text;

} CheckBoxInfos[] = {

	LOWERCASE, L"Lowercase",
	UPPERCASE, L"Uppercase",
	AUTOSORT, L"AutoSort",
	HSCROLL, L"HScroll",
	SHOWSCROLL, L"ShowScroll",
};


TestComboBoxForm::TestComboBoxForm() {

	this->CreatedEvent.Register(this, &TestComboBoxForm::OnCreated);

	m_styleFlag = 0;
	m_comboBox = nullptr;
}



void TestComboBoxForm::OnCreated(CreatedEventArgs& ev) {

	this->SetSize(600, 500);

	m_radSimple.SetText(L"Simple");
	m_radSimple.SetID(SIMPLE);
	m_radSimple.SetParent(*this);
	m_radSimple.SetSize(100, 30);
	m_radSimple.SetPosition(0, 250);
	m_radSimple.Create();
	m_radSimple.IsSelected(true);

	m_radDropDown.SetText(L"DropDown");
	m_radDropDown.SetID(DROPDOWN);
	m_radDropDown.SetParent(*this);
	m_radDropDown.SetSize(100, 30);
	m_radDropDown.SetPosition(100, 250);
	m_radDropDown.Create();

	m_radDropDownList.SetText(L"DropDownList");
	m_radDropDownList.SetID(DROPDOWNLIST);
	m_radDropDownList.SetParent(*this);
	m_radDropDownList.SetSize(150, 30);
	m_radDropDownList.SetPosition(200, 250);
	m_radDropDownList.Create();

	for (int index = 0; index < CheckBoxCount; ++index) {

		m_checkBoxs[index].SetID(CheckBoxInfos[index].ID);
		m_checkBoxs[index].SetText(CheckBoxInfos[index].Text);
		m_checkBoxs[index].SetParent(*this);
		m_checkBoxs[index].SetSize(100, 30);
		m_checkBoxs[index].SetPosition(index * 100, 280);
		m_checkBoxs[index].Create();
	}

	CreateComboBox();
}



void TestComboBoxForm::CreateComboBox() {

	if (m_comboBox != nullptr) {
		delete m_comboBox;
	}

	m_comboBox = new ComboBox();

	if ((m_styleFlag & TYPE_MASK) == SIMPLE) {
		m_comboBox->SetDropDownStyle(DropDownStyle::Simple);
	}
	else if ((m_styleFlag & TYPE_MASK) == DROPDOWN) {
		m_comboBox->SetDropDownStyle(DropDownStyle::DropDown);
	}
	else if ((m_styleFlag & TYPE_MASK) == DROPDOWNLIST) {
		m_comboBox->SetDropDownStyle(DropDownStyle::DropDownList);
	}

	m_comboBox->IsUppercase(m_styleFlag & UPPERCASE);
	m_comboBox->IsLowercase(m_styleFlag & LOWERCASE);
	m_comboBox->IsAutoHorizontalScroll(m_styleFlag & HSCROLL);
	m_comboBox->AlwaysShowScrollbar(m_styleFlag & SHOWSCROLL);
	m_comboBox->IsAutoSort(m_styleFlag & AUTOSORT);

	m_comboBox->SetSize(100, 200);
	m_comboBox->SetPosition(0, 0);
	m_comboBox->SetParent(*this);
	m_comboBox->Create();
}



LRESULT TestComboBoxForm::WndProc(const WndMsg& msg) {

	switch (msg.Message) {

	case WM_COMMAND:
		if (msg.WParamHigh == BN_CLICKED) {

			if (msg.WParamLow & TYPE_MASK) {

				m_styleFlag &= ~TYPE_MASK;
				m_styleFlag |= msg.WParamLow;

				CreateComboBox();
			}

			if (msg.WParamLow & STYLE_MASK) {

				m_styleFlag |= msg.WParamLow;

				CreateComboBox();
			}
		}
		break;
	}

	return Form::WndProc(msg);
}